﻿using System;
using System.ComponentModel.Composition;
using Expect.VisualStudio.Extensions;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Tagging;
using Microsoft.VisualStudio.Utilities;

namespace Expect.Vs2010.Extensions.Tagging
{
    [Export(typeof(IViewTaggerProvider))]
    [ContentType(Constants.ExpectContentType)]
    [TagType(typeof(FixtureSquiggleTag))]
    internal class SquiggleTaggerProvider : IViewTaggerProvider
    {
        [Import(typeof(IBufferTagAggregatorFactoryService))]
        internal IBufferTagAggregatorFactoryService TagAggregatorFactory { get; set; }

        public ITagger<T> CreateTagger<T>(ITextView textView, ITextBuffer buffer) where T : ITag
        {
            if (buffer == null)
                throw new ArgumentNullException("buffer");
            if (textView == null)
                throw new ArgumentNullException("textView");

            // Make sure we only tagging top buffer
            if (buffer != textView.TextBuffer)
                return null;

            return new SquiggleTagger(buffer, textView, TagAggregatorFactory.CreateTagAggregator<IFixtureTag>(buffer)) as ITagger<T>;
        }
    }
}
